package com.xyy.ec.qualification.pojo;

import com.xyy.ec.qualification.enums.DBTypeEnum;

import org.apache.commons.lang3.StringUtils;


public class DataSource {
    private String dbType;
    private String url;
    private String userName;
    private String password;

    /**
     * 数据校验
     * @param dataSource
     */
    public static void check(DataSource dataSource) {
        if(dataSource == null) {
            throw new RuntimeException("Init dataSource param is null !!!!");
        }

        if(StringUtils.isEmpty(dataSource.getDbType())) {
            throw new RuntimeException("Init dataSource dbType is null !!!!");
        }
        if(StringUtils.isEmpty(dataSource.getUrl())) {
            throw new RuntimeException("Init dataSource url is null !!!!");
        }
        if(isaBoolean(dataSource.getUserName(), dataSource.getDbType())) {
            throw new RuntimeException("Init dataSource userName is null !!!!");
        }
        if(isaBoolean(dataSource.getPassword(), dataSource.getDbType())) {
            throw new RuntimeException("Init dataSource password is null !!!!");
        }
    }

    private static boolean isaBoolean(String con,String dbType) {
        return StringUtils.isEmpty(con) && ! (DBTypeEnum.SQL_SERVER.getDbType().equals(dbType) || DBTypeEnum.SQL_SERVER_V2000.getDbType().equals(dbType));
    }


    public String getDbType() {
        return dbType;
    }

    public void setDbType(String dbType) {
        this.dbType = dbType;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }


}
